<template>
	<view class="container">
		<view class="example">
			<uni-forms ref="form" :model="PigTransferList" labelWidth="80px">
				<uni-forms-item label="母猪耳号" name="pigCode">
					<uni-easyinput v-model="PigTransferList.pigCode" placeholder="请输入猪只耳号" />
				</uni-forms-item>
				<uni-forms-item label="猪只类型" name="pigType" required>
					<!-- 下拉框选择 -->
					<uni-data-select v-model="PigTransferList.pigType" :localdata="pigTypes" @change="change">
					</uni-data-select>
				</uni-forms-item>


				<uni-forms-item label="转出栏舍类型" name="transferOutPhouseType" required>
					<!-- 下拉框选择 -->
					<uni-data-select v-model="PigTransferList.transferOutPhouseType" :localdata="transferOutPhouseTypes"
						@change="change">
					</uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="栏舍编码" name="transferOutPhouseCode">
					<uni-easyinput v-model="PigTransferList.transferOutPhouseCode" placeholder="请输入栏舍编码" />
				</uni-forms-item>
				<uni-forms-item label="转入栏舍类型" name="transferIntoPhouseType" required>
					<!-- 下拉框选择 -->
					<uni-data-select v-model="PigTransferList.transferIntoPhouseType"
						:localdata="transferIntoPhouseTypes" @change="change">
					</uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="栏舍编码" name="transferIntoPhouseCode">
					<uni-easyinput v-model="PigTransferList.transferIntoPhouseCode" placeholder="请输入栏舍编码" />
				</uni-forms-item>

				<view class="example-body">
					<uni-forms-item label="转舍时间" name="transferDate">
						<uni-datetime-picker type="datetime" v-model="PigTransferList.transferDate"
							@change="changeLog" />
					</uni-forms-item>
				</view>
				<uni-forms-item label="重量" name="transferPigWeight">
					<uni-easyinput v-model="PigTransferList.transferPigWeight" placeholder="请输入重量(单位 Kg)" />
				</uni-forms-item>
				<uni-forms-item label="备注">
					<uni-easyinput type="textarea" v-model="PigTransferList.remark" placeholder="请输入备注内容" />
				</uni-forms-item>
			</uni-forms>
			<button type="primary" @click="submit">提交</button>
		</view>
	</view>
</template>

<script>
	import {
		listPigTransfer,
		getPigTransfer,
		addPigTransfer,
		updatePigTransfer,
		delPigTransfer
	} from "@/api/hmy/pigTransfer";
	export default {
		name: "PigTransfer",
		dicts: ['hmy_pig_out_type', 'hmy_park_type', 'hmy_pig_type'],
		data() {
			return {
				datetimesingle: '',
				PigTransferList: {
					pigCpigTypeode: "",
					pigType: "",
					transferOutPhouseType: "",
					transferOutPhouseCode: "",
					transferIntoPhouseType: "",
					transferIntoPhouseCode: "",
					transferDate: "",
					transferPigWeight: "",
					remark: ""
				},
				pigTypes: [{
						text: '种猪',
						value: "1"
					}, {
						text: '母猪',
						value: "192"
					},
					{
						text: '肉猪',
						value: "3"
					}
				],
				transferOutPhouseTypes: [{
						text: ' 公猪舍',
						value: "1"
					},
					{
						text: ' 母猪舍',
						value: "2"
					},
					{
						text: ' 肉猪舍',
						value: "3"
					}
				],
				transferIntoPhouseTypes: [{
						text: ' 公猪舍',
						value: "1"
					},
					{
						text: ' 母猪舍',
						value: "2"
					},
					{
						text: ' 肉猪舍',
						value: "3"
					}
				],

				rules: {
					pigCode: {
						rules: [{
							required: true,
							errorMessage: '猪只耳号不能为空'
						}]
					}
				}
			}
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		methods: {
			change(e) {
				this.single = e
				console.log('change事件:', this.single = e);
			},
			changeLog(e) {
				console.log('change事件:', e);
			},
			submit(ref) {
				this.$refs.form.validate().then(res => {
					addPigTransfer(this.PigTransferList).then(response => {
						this.$modal.msgSuccess("新增成功")
						//成功后返回页面
						this.$tab.navigateTo('/pages/hmy/pigTransfer/index');
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	/* #ifndef APP-NVUE */
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		min-height: 100%;
		height: auto;
		background-color: #fcfcfc;
	}

	view {
		font-size: 16px;
		line-height: inherit;
	}

	/* #endif */
	.code {
		margin-bottom: 5px;
	}

	.icon {
		float: right;
		margin-right: 10px;
		margin-top: 5px;
	}

	.message {
		margin-top: 5px;
		color: #989897;
		line-height: 25px;
	}


	.example {
		padding: 15px;
		background-color: #fff;
	}

	.segmented-control {
		margin-bottom: 15px;
	}

	.button-group {
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}

	.form-item {
		display: flex;
		align-items: center;
		flex: 1;
	}

	.button {
		display: flex;
		align-items: center;
		height: 35px;
		line-height: 35px;
		margin-left: 10px;
	}
</style>